package com.atguigu.assionexcel.thread;

import java.util.Random;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * @author senior  关于嵌套线程Q的练习
 * @create 2021-11-27 19:21
 */
public class ThreadMethodExercise {
    public static void main(String[] args) throws InterruptedException {
        A a = new A();
        B b = new B(a);

        a.start();
        b.start();

    }
}


class A extends Thread{
private boolean loop = true;
    @Override
    public void run() {
        while (loop){
            System.out.println((int)(Math.random()*100 + 1));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public void setLoop(Boolean loop){
        this.loop = loop;
    }
}

class B extends Thread{

    private A a;
    Scanner scanner = new Scanner(System.in);
    public B(A a){
        this.a = a;
    }
    @Override
    public void run() {
        while (true){
            System.out.println("输入大写Q结束：");
            char exit = scanner.next().toUpperCase().charAt(0);
            if ('C' == exit){
                a.setLoop(false);
                System.out.println("B线程退出");
                break;
            }
        }
    }
}